<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" oninput="change(this)">
    <h1></h1>
    <script>
        // vue 双向绑定原理
        var obj = {
                name: "美的"
            }
            // Object.defineProperty(obj, "age", {
            //     value: 18,
            //     configurable: false, //能否被删除
            //     writable: false, //能否被修改
            //     enumerable: false, //能否被遍历
            // })
            // obj.age = 20;
            // delete obj.age
            // console.log(obj)
        var temp = null;
        var h1s = document.querySelector("h1")
        Object.defineProperty(obj, "age", {
            get() { //get负责赋值数据
                return temp
            },
            set(val) { //set 负责劫持数据
                console.log(val)
                temp = val;
                h1s.innerHTML = val;
            },
            configurable: true,
            enumerable: true,
        })
        obj.age = 20
        console.log(obj)

        function change(that) {
            obj.age = that.value;
        }
    </script>
</body>

</html>